<?php

class AttachController extends C {

    function upload() {
        $this->textJs("uploadify/jquery.uploadify.min.js");
        $this->textJs("uploadify/swfobject.js");
        //是否为单个上传
        $this->assign("multi", isset($_GET['multi']) ? $_GET['multi'] : 'FALSE');
        //唯一参数
        $this->assign("unique", rand(1, 999));

        $this->display("uploadForm.html");
    }

    function saveFile() {
        if ($_GET['ac'] == 'save') {
            $dbF = new csyr("files");
            $uid = $_SESSION['uid'];
            $uid = 1;
            if (empty($_GET['filepath']) || empty($_GET['type']))
                exit("nofile");
            if ($dbF->where("filepath='{$_GET['filepath']}' and uid=" . $uid)->find())
                exit("saved");
            if ($dbF->add(array('filepath' => $_GET['filepath'], 'type' => $_GET['type'], 'uid' => $uid, 'created' => time())))
                exit("saved");
            else
                exit("error");
        }
    }

    function saveNewCate() {

        if (isset($_GET['ac']) && $_GET['ac'] == 'savenewcategory') {
            if (empty($_POST['name']))
                exit("name is empty");

            $data = array(
                'name' => $_POST['name'],
                'pid' => empty($_POST['pid']) ? 0 : $_POST['pid'],
                'created' => time()
            );
            $dbCate = new csyr("category");
            if ($cid = $dbCate->add($data))
                exit("{saved:true,cid:" . $cid . "}");
            else
                exit("fail");
        }
    }

}

?>
